/*
 *  RESTful DDS is a prototyping effort to demonstrate how DDS could be combined
 *  with HTTP clients, extending the realm of pub/sub distribution to true wide
 *  area networking.
 *
 *  Copyright (C) 2009 PrismTech Ltd.
 *  reinier.torenbeek@gmail.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License Version 3 dated 29 June 2007, as published by the
 *  Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DDSTouchStone; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.opensplice.restful.service;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.Router;

public class RESTfulDDSApplication extends Application {
    
    private DDSRootProxy rootProxy;
    
    public RESTfulDDSApplication () {
        super();
        rootProxy = new DDSRootProxy();
    }
    
    /**
     * Creates a root Restlet that will receive all incoming calls.
     */
    @Override
    public synchronized Restlet createRoot() {
        // Create a router Restlet that defines routes.
        Router router = new Router(getContext());

        // TODO: Creation and deletion of datareaders
        
        router.attach("/test/{sleepTime}", TestResource.class);
        router.attach("/helloWorld", HelloWorldResource.class);
        
        // Defines a route for querying all available participants
        router.attach("/", RootResource.class);

        // Defines a route for all participant actions, like creation, querying and deletion
        router.attach("/{participantname}", ParticipantResource.class);

        // Defines a route for the resource "subscribe"
        router.attach("/{participantname}/{partitionname}/{topicname}/{typename}/subscribe",
                SubscriberResource.class);
        
        
        // Defines a route for the resource "read"
        router.attach("/{participantname}/{partitionname}/{topicname}/{typename}/subscribe/{datareadername}/read",
                ReadResource.class);
        
        // Defines a route for the resource "take"
        router.attach("/{participantname}/{partitionname}/{topicname}/{typename}/subscribe/{datareadername}/take",
                TakeResource.class);
                
        return router;
    }
    
    public DDSRootProxy getRootProxy() {
        return rootProxy;
    }

}
